<?php
/**
 * Created by PhpStorm.
 * User: qingyun
 * Date: 17/2/23
 * Time: 下午8:43
 */
namespace Lib;

class MyTree
{
    static $treeList = array();
    /**
     * 无限级分类
     * @access public
     * @param Array $data     //数据库里获取的结果集
     * @param Int $pid
     * @param Int $count       //第几级分类
     * @return Array $treeList
     */
    static public function my_tree(&$data,$pid = 0,$level = 1) {
        foreach ($data as $key => $value){
            if($value['pid']==$pid){
                $value['level'] = $level;
                self::$treeList [] = $value;
                unset($data[$key]);
                self::my_tree($data,$value['id'],$level+1);
            }
        }
        return self::$treeList;
    }
}